当前位置:  开发笔记 > 编程语言 > 正文

未定义对`boost :: iostreams :: mapped_file_source :: mapped_file_source()的引用

如何解决《未定义对`boost::iostreams::mapped_file_source::mapped_file_source()的引用》经验,为你挑选了1个好方法。

我正在测试boost的内存映射文件,但是只要boost::iostreams::mapped_file在程序中声明了,就可以:

#include  // defines ff_pipeline and ff_Pipe
#include 
#include 
#include 
#include 
#include 
#include 

#include 

#include "MapReduceJob.hpp"

using namespace ff;

int main(int argc, char* argv[]) {
    boost::iostreams::mapped_file  mf;
} 

使用这个makefile

#Fastflow and Boost paths
FF_ROOT     = ../../fastflow
BOOST_ROOT  = ../../boost_1_59_0

#Xeon's user
USR = spm1428

#Accelerator
ACC = mic0

#Program arguments
ARGS =

#Test script file
TEST = test

#file to copy on $(ACC)
FILES = file.txt foo.txt

# compiler
CC = icpc -mmic

# compiler flag
CXX = $(CC) -std=c++11 -DNO_DEFAULT_MAPPING

# compile-time flags
CFLAGS =

# header files other than /usr/include
INCLUDES = -I$(FF_ROOT)  -I$(BOOST_ROOT)

# define any libraries to link into executable:
LIBS = -pthread

#optimization flags
OPTFLAGS = -O3 -finline-functions -DNDEBUG -g -O0

# define the C source files
SRCS = Main.cpp

# define the C object files 
OBJS = $(SRCS:.cpp=.o)

# define the executable file 
MAIN = mapreduce


.PHONY: all depend clean

all:    $(MAIN) copy execute
    @echo  Simple compiler named mycc has been compiled

$(MAIN): $(OBJS) 
    $(CXX) $(CFLAGS) $(INCLUDES) $(OPTFLAGS) -o $(MAIN) $(OBJS) $(LIBS)

copy:
    scp $(FILES) $(TEST) $(MAIN) $(USR)@$(ACC):~

execute:
    ssh $(USR)@$(ACC) ./$(MAIN) $(ARGS)

test:
    ssh $(USR)@$(ACC) ./$(TEST)

.cpp.o:
    $(CXX) $(CFLAGS) $(INCLUDES) -c $<  -o $@

clean:
    $(RM) *.o *~ $(MAIN)

depend: $(SRCS)
    makedepend $(INCLUDES) $^

# DO NOT DELETE THIS LINE -- make depend needs it

我收到此编译错误:

make CC=g++ mapreduce 
g++ -std=c++11 -DNO_DEFAULT_MAPPING  -I../../fastflow  -I../../boost_1_59_0 -c Main.cpp  -o Main.o
g++ -std=c++11 -DNO_DEFAULT_MAPPING  -I../../fastflow  -I../../boost_1_59_0 -O3 -finline-functions -DNDEBUG -g -O0 -o mapreduce Main.o -pthread
Main.o: In function `boost::iostreams::mapped_file::mapped_file()':
Main.cpp:(.text._ZN5boost9iostreams11mapped_fileC2Ev[_ZN5boost9iostreams11mapped_fileC5Ev]+0x24): undefined reference to `boost::iostreams::mapped_file_source::mapped_file_source()'
collect2: error: ld returned 1 exit status
make: *** [mapreduce] Error 1

到目前为止,boost可以正常工作(例如,使用boost::posix_time::ptime Timeboost::stringref)。



1> Dovahkiin..:

您没有链接来提升。仅包括头文件只是您需要做的一半。

在您的Makefile中更改此设置:

LIBS = -pthread -L(path to boost libraries) -lboost_iostreams

这应该将boost_iostreams库链接到您的最终可执行文件。

根据您的平台和设置,您可能必须将库路径添加到环境变量。

推荐阅读
臭小子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有